//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize("Ofast","unroll-loops","inline")
#include<bits/stdc++.h>
#define ll long long
//#define int ll
#define pb push_back
using namespace std;
const int N=5e5+10,M=1e6+10,mod=998244353;
bool flag;
int n,m;
void out(int x,int y){
	if(!flag) cout<<x<<' '<<y<<'\n';
	else cout<<y<<' '<<x<<'\n';
}
signed main(){
	freopen("bishop.in","r",stdin);
	freopen("bishop.out","w",stdout);
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	cin>>n>>m;
//	//////
//	cout<<n<<' '<<m<<'\n';//del!!!!!!!!!!!
//	//////
	if(n>m) swap(n,m),flag=1;
	if(n==m){
		cout<<2*n-2<<'\n';
		for(int i=1;i<=n;i++) out(i,1);
		for(int i=2;i<n;i++) out(i,m);
		return 0;
	}
	if(n&1){
		cout<<n+m-1<<'\n';
		int p=n/2,x=1+p,y=2+p;
		int res=m-1-n;
		for(int i=0;i<res;i++) out(x,y+i);
		for(int i=1;i<=n;i++) out(i,1);
		for(int i=1;i<=n;i++) out(i,m);
	}
	else{
		int ans=m&1?n+m-1:n+m-2;
		cout<<ans<<'\n';
		int x=n/2,y=2+n/2;
		int res=ans-2*n;
		for(int i=0;i<res/2;i++) out(x,y+2*i),out(x+1,y+2*i);
		for(int i=1;i<=n;i++) out(i,1);
		for(int i=1;i<=n;i++) out(i,m);
	}
	return 0;
}
